package top.yifengxiner.blockchain.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.yifengxiner.blockchain.pojo.entity.Educated;
import top.yifengxiner.blockchain.pojo.entity.Educator;
import top.yifengxiner.blockchain.pojo.vo.BRegisterBody;
import top.yifengxiner.blockchain.service.BRegisterService;
import top.yifengxiner.blockchain.service.EducatedService;
import top.yifengxiner.blockchain.service.EducatorService;
import top.yifengxiner.common.core.pojo.AjaxResult;

/**
 * @author ：baixiao
 * @date ：Created in 2021/5/11 17:14
 * @description：登录接口
 * @modified By：
 * @version: 0.0.1$
 */
@Api("注册模块")
@RestController
@RequestMapping("/blockchain")
public class BRegisterController
{
    @Autowired
    private BRegisterService registerService;

    @Autowired
    private EducatorService educatorService;

    @Autowired
    private EducatedService educatedService;

    @ApiOperation("教育机构注册")
    @PostMapping("/educator/register")
    public AjaxResult educatorRegister(@RequestBody BRegisterBody registerBody)
    {
        Educator educator = null;
        AjaxResult ajaxResult =registerService.register(registerBody);
        if(ajaxResult.getMsg().equals("注册成功"))
        {
            educatorService.setEducator(registerBody);
            educator = educatorService.getEducatorByName(registerBody.getSubject());
        }
        return ajaxResult.setData(educator.getEducatorId());
    }

    @ApiOperation("受教育者注册")
    @PostMapping("/educated/register")
    public AjaxResult educatedRegister(@RequestBody BRegisterBody registerBody)
    {
        Educated educated = null;
        AjaxResult ajaxResult =registerService.register(registerBody);
        if(ajaxResult.getMsg().equals("注册成功"))
        {
            educatedService.setEducated(registerBody);
            educated = educatedService.getEducatedByName(registerBody.getSubject());
        }
        return ajaxResult.setData(educated.getEducatorId());
    }
}
